package common.simulation.scenarios;

import java.math.BigInteger;
import java.util.Random;

import common.configuration.Global;
import common.simulation.scenarios.Operations;
import se.sics.kompics.p2p.experiment.dsl.SimulationScenario;
import se.sics.kompics.p2p.experiment.dsl.distribution.Distribution;

@SuppressWarnings("serial")
public class Scenario3 extends Scenario {
	
        private static SimulationScenario scenario = new SimulationScenario() {{
        	
			StochasticProcess data = new StochasticProcess() {
				{
					//A Cycle consists of 5 T-Man exchanges and 5 Cyclon shuffles
					eventInterArrivalTime(constant(5000));
					raise(Global.r, Operations.peerData);
				}
			};
               
                StochasticProcess source = new StochasticProcess() {{
                        eventInterArrivalTime(constant(1));
                        raise(1, Operations.peerJoin2(Global.srcOD, true), myUniform(BigInteger.valueOf(0), BigInteger.valueOf(2).pow(20), getRandom()));
                }};
                
                
                StochasticProcess nonSource = new StochasticProcess() {{
                    eventInterArrivalTime(constant(1));
                    for(Integer i: Global.odDistr.keySet())
                    {
                    	raise(Global.odDistr.get(i), Operations.peerJoin2(i, false), myUniform(BigInteger.valueOf(0), BigInteger.valueOf(2).pow(20), getRandom()));
                    }
            }};
                source.startAt(100);
                nonSource.startAfterTerminationOf(500, source);
				data.startAfterTerminationOf(500, nonSource);
				//terminateAfterTerminationOf(1000, data);
        }};
       
//-------------------------------------------------------------------
        public Scenario3() {
                super(scenario);
                System.out.println(getRandom());
        }
        
    	public static Distribution<BigInteger> myUniform(BigInteger min, BigInteger max, Random r)
    	{
    		return new BigIntegerUniformDistribution(min, max, r);
    	}
}
